﻿using Glorysoft.Auto.Xfw;
using Glorysoft.EAP.Contracts.MESClient.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Serilog.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace Glorysoft.EAP.Contracts.MESClient
{
    public class SMECMESClient
    {
        protected readonly Logger CimLogger;
        protected readonly IConfiguration Config;

        SoapClient soapClient;
        public SMECMESClient()
        {
            CimLogger = XfwContext.LogManager.DbLogger;
            Config = XfwContext.Configuration as IConfiguration;
        }

        public LotinfoResponse GetLotInfo(RequestLotInfo request, string CarrierId, string EqpId, string UserId)
        {
            LotinfoResponse _return = new LotinfoResponse();
            var baseurl = Config.GetSection("MES").Get<string>();
            soapClient = new SoapClient(baseurl);
            Request Request = new Request();
            Request.Header = new Header()
            {
                MESSAGENAME = "LotInfoDownload",
                USERNAME = UserId,
                TRANSACTIONID = Guid.NewGuid().ToString(),
                SHOPNAME = "ASSMBLY"
            };
            Request.Body = request;
            var body = JsonConvert.SerializeObject(Request);
            string req = "";
            JsonReader readerJson = new JsonTextReader(new StringReader(JsonConvert.SerializeObject(body))); //针对转义字符特殊处理
            while (readerJson.Read())
            {
                req = readerJson.Value.ToString();
            }
            //发送http接口
            var ret = soapClient.HttpRequest("execute", req);

            //取本地json文件
            //string ret = getJsonData("./MESInterfaceTest/" + EqpId + "/GetLotInfo_Success.json");
            string reqq = string.Empty;
            foreach (char item in ret)
            {
                reqq += item.ToString();
                if (item == ',')
                {
                    reqq += "\r\n";
                }
                if (item == '{')
                {
                    reqq += "\r\n";
                }
            }
            CimLogger.Information($"{EqpId} MES<EAP.GetLotInfo() Execute. Text:{reqq}");
            //反序列化Response
            var result = JsonConvert.DeserializeObject<Response<object>>(ret);
            if (result.Header.RETURNCODE == "0")
            {
                var msgbody = JsonConvert.DeserializeObject<LotinfoResponse>(result.Body.ToString());
                _return = msgbody;
                _return.success = true;
            }
            else
            {
                _return.success = false;
                _return.msg = result.Header.RETURNMESSAGE.ToString();
            }
            return _return;
        }

        public ResponseKittingRequest KittingRequest(RequestKittingRequest request, string UserId)
        {
            ResponseKittingRequest _return = new ResponseKittingRequest();
            var baseurl = Config.GetSection("MES").Get<string>();
            soapClient = new SoapClient(baseurl);
            Request Request = new Request();
            Request.Header = new Header()
            {
                MESSAGENAME = "KittingRequest",
                USERNAME = UserId,
                TRANSACTIONID = Guid.NewGuid().ToString(),
                SHOPNAME = "ASSMBLY"
            };
            Request.Body = request;
            var body = JsonConvert.SerializeObject(Request);
            string req = "";
            JsonReader readerJson = new JsonTextReader(new StringReader(JsonConvert.SerializeObject(body))); //针对转义字符特殊处理
            while (readerJson.Read())
            {
                req = readerJson.Value.ToString();
            }
            //发送http接口
            var ret = soapClient.HttpRequest("execute", req);

            //读取本地json文件
            //string ret = getJsonData("./MESInterfaceTest/" + request.EQUIPMENTID + "/Kittinng_Success.json");

            //写log
            string reqq = string.Empty;
            foreach (char item in ret)
            {
                reqq += item.ToString();
                if (item == ',')
                {
                    reqq += "\r\n";
                }
                if (item == '{')
                {
                    reqq += "\r\n";
                }
            }
            CimLogger.Information($" MES<EAP.UnKittingRequest() Execute. Text:{reqq}");

            //反序列化Response
            var result = JsonConvert.DeserializeObject<Response<Object>>(ret);
            if (result.Header.RETURNCODE == "0")
            {
                var msgbody = JsonConvert.DeserializeObject<ResponseKittingRequest>(result.Body.ToString());
                _return = msgbody;
                _return.success = true;
            }
            else
            {
                _return.success = false;
                _return.msg = result.Header.RETURNMESSAGE.ToString();
            }
            return _return;
        }

        public BaseResponse UnKittingRequest(RequestUnKitting request, string UserId)
        {
            BaseResponse _return = new BaseResponse();
            var baseurl = Config.GetSection("MES").Get<string>();
            soapClient = new SoapClient(baseurl);
            Request Request = new Request();
            Request.Header = new Header()
            {
                MESSAGENAME = "UnKittingRequest",
                USERNAME = UserId,
                TRANSACTIONID = Guid.NewGuid().ToString(),
                SHOPNAME = "ASSMBLY"
            };
            Request.Body = request;
            var body = JsonConvert.SerializeObject(Request);
            //发送接口
            string req = "";
            JsonReader readerJson = new JsonTextReader(new StringReader(JsonConvert.SerializeObject(body))); //针对转义字符特殊处理
            while (readerJson.Read())
            {
                req = readerJson.Value.ToString();
            }
            var ret = soapClient.HttpRequest("execute", req);

            //读取本地json文件
            //string ret = getJsonData("./MESInterfaceTest/" + request.EQUIPMENTID + "/UnKittinng_Success.json");

            //写log
            string reqq = string.Empty;
            foreach (char item in ret)
            {
                reqq += item.ToString();
                if (item == ',')
                {
                    reqq += "\r\n";
                }
                if (item == '{')
                {
                    reqq += "\r\n";
                }
            }
            CimLogger.Information($" MES<EAP.UnKittingRequest() Execute. Text:{reqq}");

            //反序列化Response
            var result = JsonConvert.DeserializeObject<Response<Object>>(ret);
            if (result.Header.RETURNCODE == "0")
            {
                _return.success = true;
            }
            else
            {
                _return.success = false;
                _return.msg = result.Header.RETURNMESSAGE.ToString();
            }
            return _return;
        }

        public EquipmentListResponse GetEqpList(RequestEQPList request)
        {
            EquipmentListResponse _return = new EquipmentListResponse();
            var baseurl = Config.GetSection("MES").Get<string>();
            soapClient = new SoapClient(baseurl);
            Request Request = new Request();
            Request.Header = new Header() { MESSAGENAME = "GetEquipmentList" };
            Request.Body = request;
            var body = JsonConvert.SerializeObject(Request);
            //发送http接口
            var ret = soapClient.HttpRequest("GetEquipmentList", JsonConvert.SerializeObject(body));

            //反序列化Response
            var result = JsonConvert.DeserializeObject<Response<object>>(ret);
            if (result.Header.RETURNCODE == "0")
            {
                var msgbody = JsonConvert.DeserializeObject<EquipmentListResponse>(result.Body.ToString());
                _return = msgbody;
                _return.success = true;
            }
            else
            {
                _return.success = false;
                _return.msg = result.Header.RETURNMESSAGE.ToString();
            }
            return _return;
        }
        public BaseResponse LotTrackIn(RequestTrackIn request, string UserId)
        {
            BaseResponse _return = new BaseResponse();
            var baseurl = Config.GetSection("MES").Get<string>();
            soapClient = new SoapClient(baseurl);
            Request Request = new Request();
            Request.Header = new Header()
            {
                MESSAGENAME = "TrackIn",
                USERNAME = UserId,
                TRANSACTIONID = Guid.NewGuid().ToString(),
                SHOPNAME = "ASSMBLY"
            };
            Request.Body = request;
            var body = JsonConvert.SerializeObject(Request);
            string req = "";
            JsonReader readerJson = new JsonTextReader(new StringReader(JsonConvert.SerializeObject(body))); //针对转义字符特殊处理
            while (readerJson.Read())
            {
                req = readerJson.Value.ToString();
            }
            //发送http接口
            var ret = soapClient.HttpRequest("execute", req);

            //读取本地json文件
            //string ret = getJsonData("./MESInterfaceTest/" + request.EQUIPMENTID + "/TrackIn_Success.json");

            //写log
            string reqq = string.Empty;
            foreach (char item in ret)
            {
                reqq += item.ToString();
                if (item == ',')
                {
                    reqq += "\r\n";
                }
                if (item == '{')
                {
                    reqq += "\r\n";
                }
            }
            CimLogger.Information($" MES<EAP.LotTrackIn() Execute. Text:{reqq}");

            //反序列化Response
            var result = JsonConvert.DeserializeObject<Response<Object>>(ret);
            if (result.Header.RETURNCODE == "0")
            {
                _return.success = true;
            }
            else
            {
                _return.success = false;
                _return.msg = result.Header.RETURNMESSAGE.ToString();
            }
            return _return;
        }
        public BaseResponse LotTrackOut(RequestTrackOut request, string UserId)
        {
            BaseResponse _return = new BaseResponse();
            var baseurl = Config.GetSection("MES").Get<string>();
            soapClient = new SoapClient(baseurl);
            Request Request = new Request();
            Request.Header = new Header()
            {
                MESSAGENAME = "TrackOut",
                USERNAME = UserId,
                TRANSACTIONID = Guid.NewGuid().ToString(),
                SHOPNAME = "ASSMBLY"
            };
            Request.Body = request;

            var body = JsonConvert.SerializeObject(Request);
            //发送接口
            string req = "";
            JsonReader readerJson = new JsonTextReader(new StringReader(JsonConvert.SerializeObject(body))); //针对转义字符特殊处理
            while (readerJson.Read())
            {
                req = readerJson.Value.ToString();
            }
            var ret = soapClient.HttpRequest("execute", req);

            //读取本地json文件
            //string ret = getJsonData("./MESInterfaceTest/" + request.EQUIPMENTID + "/TrackOut_Success.json");

            //写log
            string reqq = string.Empty;
            foreach (char item in ret)
            {
                reqq += item.ToString();
                if (item == ',')
                {
                    reqq += "\r\n";
                }
                if (item == '{')
                {
                    reqq += "\r\n";
                }
            }
            CimLogger.Information($" MES<EAP.LotTrackOut() Execute. Text:{reqq}");

            //反序列化Response
            var result = JsonConvert.DeserializeObject<Response<Object>>(ret);
            if (result.Header.RETURNCODE == "0")
            {
                _return.success = true;
            }
            else
            {
                _return.success = false;
                _return.msg = result.Header.RETURNMESSAGE.ToString();
            }
            return _return;
        }
        public BaseResponse HoldLot(RequestHoldLot request, string UserId)
        {
            BaseResponse _return = new BaseResponse();
            var baseurl = Config.GetSection("MES").Get<string>();
            soapClient = new SoapClient(baseurl);
            Request Request = new Request();
            Request.Header = new Header()
            {
                MESSAGENAME = "HoldLot",
                USERNAME = UserId,
                TRANSACTIONID = Guid.NewGuid().ToString(),
                SHOPNAME = "ASSMBLY"
            };
            Request.Body = request;
            var body = JsonConvert.SerializeObject(Request);
            //发送接口
            string req = "";
            JsonReader readerJson = new JsonTextReader(new StringReader(JsonConvert.SerializeObject(body))); //针对转义字符特殊处理
            while (readerJson.Read())
            {
                req = readerJson.Value.ToString();
            }
            var ret = soapClient.HttpRequest("execute", req);

            //读取本地json文件
            //string ret = getJsonData("./MESInterfaceTest/" + request.equipmentId + "/HoldLot_Success.json");

            //写log
            string reqq = string.Empty;
            foreach (char item in ret)
            {
                reqq += item.ToString();
                if (item == ',')
                {
                    reqq += "\r\n";
                }
                if (item == '{')
                {
                    reqq += "\r\n";
                }
            }
            CimLogger.Information($" MES<EAP.HoldLot() Execute. Text:{reqq}");

            //反序列化Response
            var result = JsonConvert.DeserializeObject<Response<Object>>(ret);
            if (result.Header.RETURNCODE == "0")
            {
                _return.success = true;
            }
            else
            {
                _return.success = false;
                _return.msg = result.Header.RETURNMESSAGE.ToString();
            }
            return _return;
        }
        public BaseResponse ConfirmLogin(RequestLogin request, string UserId)
        {
            BaseResponse _return = new BaseResponse();
            Request Request = new Request();
            Request.Header = new Header()
            {
                MESSAGENAME = "UserLogin",
                USERNAME = UserId,
                TRANSACTIONID = Guid.NewGuid().ToString(),
                SHOPNAME = "ASSMBLY"
            };
            Request.Body = request;
            var body = JsonConvert.SerializeObject(Request);
            var baseurl = Config.GetSection("MES").Get<string>();
            soapClient = new SoapClient(baseurl);
            string req = "";
            JsonReader readerJson = new JsonTextReader(new StringReader(JsonConvert.SerializeObject(body))); //针对转义字符特殊处理
            while (readerJson.Read())
            {
                req = readerJson.Value.ToString();
            }

            var ret = soapClient.HttpRequest("execute", req);

            //读取本地json文件
            //string ret = getJsonData("./MESInterfaceTest/" + request.EQUIPMENTID + "/Login_Success.json");

            //写log
            string reqq = string.Empty;
            foreach (char item in ret)
            {
                reqq += item.ToString();
                if (item == ',')
                {
                    reqq += "\r\n";
                }
                if (item == '{')
                {
                    reqq += "\r\n";
                }
            }
            CimLogger.Information($" MES<EAP.UserLogin() Execute. Text:{reqq}");

            //反序列化Response
            var result = JsonConvert.DeserializeObject<Response<Object>>(ret);
            if (result.Header.RETURNCODE == "0")
            {
                _return.success = true;
            }
            else
            {
                _return.success = false;
                _return.msg = result.Header.RETURNMESSAGE.ToString();
            }
            return _return;
        }
        public BaseResponse AlarmReport(RequestAlarmReport request, string UserId)
        {
            BaseResponse _return = new BaseResponse();
            var baseurl = Config.GetSection("MES").Get<string>();
            soapClient = new SoapClient(baseurl);
            Request Request = new Request();
            Request.Header = new Header()
            {
                MESSAGENAME = "AlarmReport",
                USERNAME = UserId,
                TRANSACTIONID = Guid.NewGuid().ToString(),
                SHOPNAME = "ASSMBLY"
            };
            Request.Body = request;
            var body = JsonConvert.SerializeObject(Request);
            //发送接口
            string req = "";
            JsonReader readerJson = new JsonTextReader(new StringReader(JsonConvert.SerializeObject(body))); //针对转义字符特殊处理
            while (readerJson.Read())
            {
                req = readerJson.Value.ToString();
            }

            var ret = soapClient.HttpRequest("execute", req);

            //读取本地json文件
            //string ret = getJsonData("./MESInterfaceTest/" + request.EQUIPMENTID + "/Alarm_Success.json");

            //写log
            string reqq = string.Empty;
            foreach (char item in ret)
            {
                reqq += item.ToString();
                if (item == ',')
                {
                    reqq += "\r\n";
                }
                if (item == '{')
                {
                    reqq += "\r\n";
                }
            }
            CimLogger.Information($" MES<EAP.AlarmReport() Execute. Text:{reqq}");

            //反序列化Response
            var result = JsonConvert.DeserializeObject<Response<Object>>(ret);
            if (result.Header.RETURNCODE == "0")
            {
                _return.success = true;
            }
            else
            {
                _return.success = false;
                _return.msg = result.Header.RETURNMESSAGE.ToString();
            }
            return _return;
        }
        public BaseResponse ToolChange(RequestToolChange request, string UserId)
        {
            BaseResponse _return = new BaseResponse();
            var baseurl = Config.GetSection("MES").Get<string>();
            soapClient = new SoapClient(baseurl);
            Request Request = new Request();
            Request.Header = new Header()
            {
                MESSAGENAME = "AlarmReport",
                USERNAME = UserId,
                TRANSACTIONID = Guid.NewGuid().ToString(),
                SHOPNAME = "ASSMBLY"
            };
            Request.Body = request;
            var body = JsonConvert.SerializeObject(Request);
            //发送接口
            string req = "";
            JsonReader readerJson = new JsonTextReader(new StringReader(JsonConvert.SerializeObject(body))); //针对转义字符特殊处理
            while (readerJson.Read())
            {
                req = readerJson.Value.ToString();
            }
            var ret = soapClient.HttpRequest("execute", req);

            //读取本地json文件
            //string ret = getJsonData("./MESInterfaceTest/" + request.EqpId + "/ToolChange_Success.json");

            //反序列化Response
            var result = JsonConvert.DeserializeObject<BaseResponse>(ret);
            if (result.success)
            {
                _return.success = result.success;
            }
            else
            {
                _return.success = result.success;
                _return.msg = result.msg.ToString();
            }
            return _return;
        }
        public BaseResponse GetDieSitInWafer(RequestDieSiteWafer request, string UserId)
        {
            BaseResponse _return = new BaseResponse();
            var baseurl = Config.GetSection("MES").Get<string>();
            soapClient = new SoapClient(baseurl);
            Request Request = new Request();
            Request.Header = new Header()
            {
                MESSAGENAME = "DieBindDCBRequest",
                USERNAME = UserId,
                TRANSACTIONID = Guid.NewGuid().ToString(),
                SHOPNAME = "ASSMBLY"
            };
            Request.Body = request;
            var body = JsonConvert.SerializeObject(Request);
            //发送接口
            string req = "";
            JsonReader readerJson = new JsonTextReader(new StringReader(JsonConvert.SerializeObject(body))); //针对转义字符特殊处理
            while (readerJson.Read())
            {
                req = readerJson.Value.ToString();
            }
            var ret = soapClient.HttpRequest("execute", req);
            //读取本地json文件
            //string ret = getJsonData("./MESInterfaceTest/" + "MFWB002"+ "/EDCUpload_Success.json");

            //写log
            string reqq = string.Empty;
            foreach (char item in ret)
            {
                reqq += item.ToString();
                if (item == ',')
                {
                    reqq += "\r\n";
                }
                if (item == '{')
                {
                    reqq += "\r\n";
                }
            }
            CimLogger.Information($" MES<EAP.DieBindDCBRequest() Execute. Text:{reqq}");

            //反序列化Response
            var result = JsonConvert.DeserializeObject<Response<Object>>(ret);
            if (result.Header.RETURNCODE == "0")
            {
                _return.success = true;
            }
            else
            {
                _return.success = false;
                _return.msg = result.Header.RETURNMESSAGE.ToString();
            }
            return _return;
        }
        public BaseResponse EDCDataReport(RequestEDCDataReport request, string UserId)
        {
            BaseResponse _return = new BaseResponse();
            var baseurl = Config.GetSection("MES").Get<string>();
            soapClient = new SoapClient(baseurl);
            Request Request = new Request();
            Request.Header = new Header()
            {
                MESSAGENAME = "ProcessDataReport",
                USERNAME = UserId,
                TRANSACTIONID = Guid.NewGuid().ToString(),
                SHOPNAME = "ASSMBLY"
            };
            Request.Body = request;
            var body = JsonConvert.SerializeObject(Request);
            //发送接口
            string req = "";
            JsonReader readerJson = new JsonTextReader(new StringReader(JsonConvert.SerializeObject(body))); //针对转义字符特殊处理
            while (readerJson.Read())
            {
                req = readerJson.Value.ToString();
            }
            var ret = soapClient.HttpRequest("execute", req);
            //读取本地json文件
            //string ret = getJsonData("./MESInterfaceTest/" + "MFWB002" + "/EDCUpload_Success.json");

            //写log
            string reqq = string.Empty;
            foreach (char item in ret)
            {
                reqq += item.ToString();
                if (item == ',')
                {
                    reqq += "\r\n";
                }
                if (item == '{')
                {
                    reqq += "\r\n";
                }
            }
            CimLogger.Information($" MES<EAP.ProcessDataReport() Execute. Text:{reqq}");

            //反序列化Response
            var result = JsonConvert.DeserializeObject<Response<Object>>(ret);
            if (result.Header.RETURNCODE == "0")
            {
                _return.success = true;
            }
            else
            {
                _return.success = false;
                _return.msg = result.Header.RETURNMESSAGE.ToString();
            }
            return _return;
        }

        public BaseResponse GetBinRerult(RequestBinDataReport request, string UserId)
        {
            BaseResponse _return = new BaseResponse();
            var baseurl = Config.GetSection("MES").Get<string>();
            soapClient = new SoapClient(baseurl);
            Request Request = new Request();
            Request.Header = new Header()
            {
                MESSAGENAME = "BinResultReport",
                USERNAME = UserId,
                TRANSACTIONID = Guid.NewGuid().ToString(),
                SHOPNAME = "ASSMBLY"
            };
            Request.Body = request;
            var body = JsonConvert.SerializeObject(Request);
            //发送接口
            string req = "";
            JsonReader readerJson = new JsonTextReader(new StringReader(JsonConvert.SerializeObject(body))); //针对转义字符特殊处理
            while (readerJson.Read())
            {
                req = readerJson.Value.ToString();
            }
            var ret = soapClient.HttpRequest("execute", req);
            //读取本地json文件
            //string ret = getJsonData("./MESInterfaceTest/" + request.EqpId + "/EDCUpload_Success.json");

            //写log
            string reqq = string.Empty;
            foreach (char item in ret)
            {
                reqq += item.ToString();
                if (item == ',')
                {
                    reqq += "\r\n";
                }
                if (item == '{')
                {
                    reqq += "\r\n";
                }
            }
            CimLogger.Information($" MES<EAP.GetBinRerult() Execute. Text:{reqq}");

            //反序列化Response
            var result = JsonConvert.DeserializeObject<Response<Object>>(ret);
            if (result.Header.RETURNCODE == "0")
            {
                _return.success = true;
            }
            else
            {
                _return.success = false;
                _return.msg = result.Header.RETURNMESSAGE.ToString();
            }
            return _return;
        }
        public BaseResponse EQPSynchronization(RequestEQPList request)
        {
            BaseResponse _return = new BaseResponse();
            var body = JsonConvert.SerializeObject(request);
            //发送接口
            //var ret = soapClient.HttpRequest("requestMessage=" + JsonConvert.SerializeObject(body));

            //读取本地json文件
            string ret = getJsonData("./MESInterfaceTest/" + request.EqpId + "/GetEqpList_Success.json");


            //反序列化Response
            var result = JsonConvert.DeserializeObject<BaseResponse>(ret);
            if (result.success)
            {
                _return.success = result.success;
            }
            else
            {
                _return.success = result.success;
                //_return.msg = result.Header.RETURNMESSAGE.ToString();
            }
            return _return;
        }
        public string getJsonData(string path)
        {
            string content = string.Empty;
            using (StreamReader sr = File.OpenText(path))
            {
                content = sr.ReadToEnd().Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\t", string.Empty);
            }
            return content;
        }
        public BaseResponse CheckCardSlotAndMaterial(RequestCheckCardSlotAndMaterial request, string UserId)
        {
            BaseResponse _return = new BaseResponse();
            var baseurl = Config.GetSection("MES").Get<string>();
            soapClient = new SoapClient(baseurl);
            Request Request = new Request();
            Request.Header = new Header()
            {
                MESSAGENAME = "CheckCardSlotAndMaterial",
                USERNAME = UserId,
                TRANSACTIONID = Guid.NewGuid().ToString(),
                SHOPNAME = "ASSMBLY"
            };
            Request.Body = request;
            var body = JsonConvert.SerializeObject(Request);
            //发送接口
            string req = "";
            JsonReader readerJson = new JsonTextReader(new StringReader(JsonConvert.SerializeObject(body))); //针对转义字符特殊处理
            while (readerJson.Read())
            {
                req = readerJson.Value.ToString();
            }
            var ret = soapClient.HttpRequest("execute", req);
            //读取本地json文件
            //string ret = getJsonData("./MESInterfaceTest/" + "MFWB002" + "/CheckCardSlotAndMaterial_Success.json");
            //写log
            string reqq = string.Empty;
            foreach (char item in ret)
            {
                reqq += item.ToString();
                if (item == ',')
                {
                    reqq += "\r\n";
                }
                if (item == '{')
                {
                    reqq += "\r\n";
                }
            }
            CimLogger.Information($" MES<EAP.CheckCardSlotAndMaterial() Execute. Text:{reqq}");
            //反序列化Response
            var result = JsonConvert.DeserializeObject<FeedAndMaterialResponse<object>>(ret);
            if (result.Body.RESULT == "0")
            {
                _return.success = true;
            }
            else
            {
                _return.success = false;
                _return.msg = result.Body.RESULTMASSAGE.ToString();
            }
            return _return;
        }

        public BaseResponse GetAllSite(RequesGetAllSite request, string UserId)
        {
            BaseResponse _return = new BaseResponse();
            var baseurl = Config.GetSection("MES").Get<string>();
            soapClient = new SoapClient(baseurl);
            Request Request = new Request();
            Request.Header = new Header()
            {
                MESSAGENAME = "GetAllSite",
                USERNAME = UserId,
                TRANSACTIONID = Guid.NewGuid().ToString(),
                SHOPNAME = "ASSMBLY"
            };
            Request.Body = request;
            var body = JsonConvert.SerializeObject(Request);
            //发送接口
            string req = "";
            JsonReader readerJson = new JsonTextReader(new StringReader(JsonConvert.SerializeObject(body))); //针对转义字符特殊处理
            while (readerJson.Read())
            {
                req = readerJson.Value.ToString();
            }
            var ret = soapClient.HttpRequest("execute", req);
            //读取本地json文件
            //string ret = getJsonData("./MESInterfaceTest/" + "MFWB002" + "/GetAllSite_Success.json");
            //写log
            string reqq = string.Empty;
            foreach (char item in ret)
            {
                reqq += item.ToString();
                if (item == ',')
                {
                    reqq += "\r\n";
                }
                if (item == '{')
                {
                    reqq += "\r\n";
                }
            }
            CimLogger.Information($" MES<EAP.GetAllSite() Execute. Text:{reqq}");

            //反序列化Response
            var result = JsonConvert.DeserializeObject<Response<Object>>(ret);
            if (result.Header.RETURNCODE == "0")
            {
                _return.success = true;
            }
            else
            {
                _return.success = false;
                _return.msg = result.Header.RETURNMESSAGE.ToString();
            }
            return _return;
        }
        /// <summary>
        /// RMS 同步MES用户名
        /// </summary>
        /// <returns></returns>
        public ResponseMesUserInfo GetSynMesUser()
        {
            ResponseMesUserInfo _return = new ResponseMesUserInfo();
            var baseurl = Config.GetSection("MES").Get<string>();
            soapClient = new SoapClient(baseurl);
            Request Request = new Request();
            Request.Header = new Header()
            {
                MESSAGENAME = "GetUserInfoRequest",
                USERNAME = "admin",
                TRANSACTIONID = Guid.NewGuid().ToString(),
                SHOPNAME = "ASSMBLY"
            };
            var body = JsonConvert.SerializeObject(Request.Body);
            //发送接口
            string req = "";
            JsonReader readerJson = new JsonTextReader(new StringReader(JsonConvert.SerializeObject(body))); //针对转义字符特殊处理
            while (readerJson.Read())
            {
                req = readerJson.Value.ToString();
            }
            //var ret = soapClient.HttpRequest("execute", req);
            //读取本地json文件
            string ret = getJsonData("./MESInterfaceTest/" + "MFPC001" + "/GetUserInfoRequest_Success.json");
            //写log
            string reqq = string.Empty;
            foreach (char item in ret)
            {
                reqq += item.ToString();
                if (item == ',')
                {
                    reqq += "\r\n";
                }
                if (item == '{')
                {
                    reqq += "\r\n";
                }
            }
            CimLogger.Information($" MES<EAP.GetSynEmsUser() Execute. Text:{reqq}");

            //反序列化Response
            var result = JsonConvert.DeserializeObject<Response<Object>>(ret);
            if (result.Header.RETURNCODE == "0")
            {
                var msgbody = JsonConvert.DeserializeObject<ResponseMesUserInfo>(result.Body.ToString());
                _return = msgbody;
                _return.success = true;
            }
            else
            {
                _return.success = false;
                _return.msg = result.Header.RETURNMESSAGE.ToString();
            }
            return _return;
        }
    }
}
